//=======================================================================
// The Primary Siege Gametype
//=======================================================================
class TFGame extends UTTeamGame
    config(game);

var config int	BountyAmount;
var config int	OutpostDist;
var config int	StartupResources;
var config int	BuildLimit;
var config int	OutpostArea;
var config int	GeneratorRate;
var config bool	BuildAreas;
var config int	MinimumIncome;
var config int  SkillAmount;
var config bool ToggleWarhead;
var config bool FastBuildTime;
var config bool Terr;
var config int  MaxSentinel;
var config bool AllowUpgrades;
var config bool UnlimitedRES;

const SIGPROPNUM = 15;
var localized string SIGPropsDisplayText[SIGPROPNUM];
var localized string SIGPropDescText[SIGPROPNUM];

var() class<weapon> DefWeapons[4];

//////////////////////////////////////////////////////NEED UT3 ALT. to "PlayInfo", Possibly move to game rules//////////////////////////////
/*static function FillPlayInfo(PlayInfo PlayInfo)
{
	local int i;

	Super.FillPlayInfo(PlayInfo);  // Always begin with calling parent

	PlayInfo.AddSetting(default.GameGroup, "BountyAmount", default.SIGPropsDisplayText[i++], 40, 1, "Text", "5;0:99999");
	PlayInfo.AddSetting(default.GameGroup, "OutpostDist", default.SIGPropsDisplayText[i++], 40, 1, "Text", "5;0:99999");
	PlayInfo.AddSetting(default.GameGroup, "StartupResources", default.SIGPropsDisplayText[i++], 40, 1, "Text", "5;0:3000");
	PlayInfo.AddSetting(default.GameGroup, "BuildLimit", default.SIGPropsDisplayText[i++], 40, 1, "Text", "5;0:99999");
	PlayInfo.AddSetting(default.GameGroup, "OutpostArea", default.SIGPropsDisplayText[i++], 40, 1, "Text", "5;0:99999");
	PlayInfo.AddSetting(default.GameGroup, "GeneratorRate", default.SIGPropsDisplayText[i++], 40, 1, "Text", "5;0:99999");
    PlayInfo.AddSetting(default.GameGroup, "BuildAreas",    default.SIGPropsDisplayText[i++], 0,  1, "Check",        ,,     , false);
    PlayInfo.AddSetting(default.GameGroup, "MinimumIncome", default.SIGPropsDisplayText[i++], 40, 1, "Text", "5;0:99999");
	PlayInfo.AddSetting(default.GameGroup, "SkillAmount", default.SIGPropsDisplayText[i++], 40, 1, "Text", "5;0:99999");
    PlayInfo.AddSetting(default.GameGroup, "ToggleWarhead", default.SIGPropsDisplayText[i++], 0,  1, "Check",        ,,     , false);
	PlayInfo.AddSetting(default.GameGroup, "FastBuildTime", default.SIGPropsDisplayText[i++], 0,  1, "Check",        ,,     , true);
	PlayInfo.AddSetting(default.GameGroup, "Terr", default.SIGPropsDisplayText[i++], 0,  1, "Check",        ,,     , false);
	PlayInfo.AddSetting(default.GameGroup, "MaxSentinel", default.SIGPropsDisplayText[i++], 40, 1, "Text", "5;0:20");
	PlayInfo.AddSetting(default.GameGroup, "AllowUpgrades", default.SIGPropsDisplayText[i++], 0,  1, "Check",        ,,     , false);
	PlayInfo.AddSetting(default.GameGroup, "UnlimitedRES", default.SIGPropsDisplayText[i++], 0,  1, "Check",        ,,     , true);
}

static event string GetDescriptionText(string PropName)
{
	switch (PropName)
	{
		case "BountyAmount":	return default.SIGPropDescText[0];
		case "OutpostDist":	return default.SIGPropDescText[1];
		case "StartupResources":	return default.SIGPropDescText[2];
		case "BuildLimit":	return default.SIGPropDescText[3];
		case "OutpostArea":	return default.SIGPropDescText[4];
		case "GeneratorRate":	return default.SIGPropDescText[5];
        case "BuildAreas":	return default.SIGPropDescText[6];
        case "MinimumIncome":	return default.SIGPropDescText[7];
		case "SkillAmount":	return default.SIGPropDescText[8];
		case "ToggleWarhead": return default.SIGPropDescText[9];
		case "FastBuildTime": return default.SIGPropDescText[10];
		case "Terr": return default.SIGPropDescText[11];
		case "MaxSentinel": return default.SIGPropDescText[12];
		case "AllowUpgrades": return default.SIGPropDescText[13];
		case "UnlimitedRES": return default.SIGPropDescText[14];
	}

	return Super.GetDescriptionText(PropName);
}*/

function AddDefaultInventory( pawn PlayerPawn )
{

    local Weapon newWeapon;
    local int i;

    for(i=0;i<3;i++)
	{
    	if( (DefWeapons[i]!=None) && (PlayerPawn.FindInventoryType(DefWeapons[i])==None) )
    	{
    	    newWeapon = Spawn(DefWeapons[i],,,PlayerPawn.Location);
   	 	    if( newWeapon != none )
    	    {
   		        newWeapon.GiveTo(PlayerPawn);
    	        newWeapon.bCanThrow = false;
      	  	}
  		}
	}

    SetPlayerDefaults(PlayerPawn);

    //reset players stats
	if(TFPRI(playerpawn.Controller.PlayerReplicationInfo)!=none)
	{
	    TFPRI(playerpawn.Controller.PlayerReplicationInfo).resetabilities();

        TFPRI(playerpawn.Controller.PlayerReplicationInfo).credits+=
        TFGRI(WorldInfo.Game.GameReplicationInfo).teamcredits[playerpawn.Controller.PlayerReplicationInfo.team.teamindex];
    }
}

////////////////////////////////////////////////Abilities are not in use, do not add unless we decide to use them////////////////////////
/*function prebeginplay()
{
    Class'Engine.Player'.default.ComboNameList[0]="TaskForces.ComboPower";
    Class'Engine.Player'.default.ComboNameList[1]="TaskForces.ComboDurability";
    Class'Engine.Player'.default.ComboNameList[2]="TaskForces.ComboAgility";
    Class'Engine.Player'.default.ComboNameList[3]="TaskForces.ComboBoost";

    super.prebeginplay();
}*/

event Supersuper( string Options, out string Error )
{
    super.InitGame(options, error);
}

simulated event InitGame( string Options, out string Error )
{
    super.InitGame(options, error);

    SaveConfig();
    AddMutator("TaskForces.TFMainMut",true);
}

function bool GiveWeaponTo(string aClassName, pawn Playerpawn)
{
    local class<Weapon> WeaponClass;
	local Weapon NewWeapon;

	WeaponClass = class<Weapon>(DynamicLoadObject(aClassName, class'Class'));

	if( playerpawn.FindInventoryType(WeaponClass) != none )
		return false;
	newWeapon = playerpawn.Spawn(WeaponClass);
	if( newWeapon != none )
	{
		newWeapon.GiveTo(playerpawn);
	    return true;
    }
}

/////////////////////////////////////////////////////////////////////////Add damage types when they exist//////////////////////////////
//Damage on players only - no damage management for stations here
function ReduceDamage( out int Damage, pawn injured, Controller instigatedBy, vector HitLocation, out vector Momentum, class<DamageType> DamageType )
{
    //local int td, ta;                                                     //td and ta are used in conjuntion with Damage types//
    local TFPRI pri;
    local float tmp, factor;

    factor=1;

    //ta=7;
    //td=7;

    if(injured!=none && injured.PlayerReplicationInfo!=none)
    {
        //td=injured.PlayerReplicationInfo.Team.TeamIndex;
        pri=TFPRI(injured.playerreplicationinfo);
    }

    //if(instigatedby!=none && injured!=instigatedby && instigatedBy.PlayerReplicationInfo!=none /*&& DamageType!=class'TaskForces.DamTypeGenFlash'*/) ta=instigatedBy.PlayerReplicationInfo.Team.TeamIndex;

    /*if(((DamageType==class'TaskForces.DamTypeProtR' || DamageType==class'TaskForces.DamTypeGuardProjR') && td==0) || ((DamageType==class'TaskForces.DamTypeProtB' || DamageType==class'TaskForces.DamTypeGuardProjB') && td==1))
       return damage=0; */

    //Durability
	if(pri!=none) factor/=pri.calcFactor(1);

    //Power
    if(instigatedby!=none) pri=TFPRI(instigatedBy.playerreplicationinfo);
    if(pri!=none) factor*=pri.calcFactor(0);

    tmp=damage*factor;
    damage*=factor;
    tmp-=damage;
    if(tmp<1 && frand()<tmp) tmp=1;
        damage+=tmp;
	return;
}

//////////////////////////////////////////////////////Find UT3 ScoreEvent Alternative////////////////////////////////////////////////////////
//scores for kills
function ScoreKill(Controller Killer, Controller Other)
{
    //suicide , recieve penalty
    if( (killer == Other) || (killer == None) )
	{
    	if (Other!=None)
        {
    	    TFPRI(other.PlayerReplicationInfo).SubSkill(-50);
		    TFPRI(other.PlayerReplicationInfo).SubRes(-BountyAmount*2);
            Other.PlayerReplicationInfo.Score -= 2;
		    //ScoreEvent(Other.PlayerReplicationInfo,-2,"self_frag");
	    }
    }
    else if ( killer.PlayerReplicationInfo != None )
	{   //Add frag to killers score
		Killer.PlayerReplicationInfo.Kills++;

        //teamkill, recieve penalty
        if(Killer.PlayerReplicationInfo.Team == Other.PlayerReplicationInfo.Team)
        {
            Killer.PlayerReplicationInfo.Score-=1;
            TFPRI(killer.PlayerReplicationInfo).SubSkill(-25);
            TFPRI(killer.PlayerReplicationInfo).SubRes(-BountyAmount);
            //ScoreEvent(Killer.PlayerReplicationInfo, -1,"team_frag");
		}
		else //killed enemy, gain score
		{
            Killer.PlayerReplicationInfo.Score+=1;
		    TFPRI(killer.PlayerReplicationInfo).AddSkill(SkillAmount);
		    TFPRI(killer.PlayerReplicationInfo).AddRes(BountyAmount);
            //ScoreEvent(Killer.PlayerReplicationInfo,1,"frag");
        }
	}

    //calculate score
    if ( GameRulesModifiers != none )
    {
        GameRulesModifiers.ScoreKill(Killer, Other);
    }
}


function StartMatch()
{
    local teaminfo t;
    local TFGRI gri;
    super.StartMatch();

    foreach allactors( class'teaminfo', t)
	{
	    if(TFGRI(gamereplicationinfo).team[t.teamindex]==none)
        TFGRI(gamereplicationinfo).team[t.teamindex]=t;
    }

    gri=TFGRI(gamereplicationinfo);
    gri.AddTeamRes(startupResources, 0, true);
    gri.AddTeamRes(startupResources, 1, true);
    gri.MaxControl[0]=BuildLimit;
    gri.MaxControl[1]=BuildLimit;
}

defaultproperties
{
    bPlayersBalanceTeams=True
    NumBots=0
    bPlayersMustBeReady=True
    bAutoNumBots=False
    bPlayersVsBots=False
    bScoreTeamKills=False                                                               //players don't gain score for team kills
    bSpawnInTeamArea=True                                                               //players spawn in areas designated for their team
    bScoreVictimsTarget=True                                                            //players gain score from killing enemies
    bUndrivenVehicleDamage=True                                                         //vehicles that arn't being driven can take damage
    bAllowTranslocator=False                                                          //disallows translocator
    Description="Destroy the enemy Core!"                                               //description of the gametype
    bScoreDeaths=False                                                                  //players don't recieve score change for deaths
    MapPrefixes(0)="CTF"                                                                //map prefix used for gametype
    MapPrefixes(1)="VCTF"                                                               //map prefix used for gametype
    EndOfMatchRulesTemplateStr_Scoring="First team to destroy the enemy core wins"      //goal message for game with no time limit
    EndOfMatchRulesTemplateStr_Time="Team with the highest score in `t mins. wins"      //goal message for game with time limit
    MidgameScorePanelTag="TDMPanel"                                                     //scoreboard type
    GameName="Siege"                                                                    //name of gametype
    GoalScore=20                                                                        //Goal Score
    TimeLimit=15                                                                        //Time limit
    DeathMessageClass=Class'UTGame.UTTeamDeathMessage'                                  //death message
    PlayerReplicationInfoClass=class'TaskForces.TFPRI'                                  //sets the PRI to the Siege PRI
    GameReplicationInfoClass=class'TaskForces.TFGRI'                                    //sets the GRI to the Siege GRI
	PlayerControllerClass=class'TaskForces.TFPlayerController'                          //sets the player controller to the Siege PC
	ConsolePlayerControllerClass=class'UTGame.UTConsolePlayerController'                //sets the console player controller
    DefaultPawnClass=class'TaskForces.TFPawn'                                           //sets the game pawn to the Siege pawn
	BotClass=class'UTBot'                                                               //sets the default bot class
   	Acronym="SG"                                                                        //An acronym for something?
  	HUDType=class'TaskForces.TFTeamHUD'                                                 //sets the HUD to the Siege HUD
    DefWeapons(0)=Class'UTGame.UTWeap_LinkGun'
    DefWeapons(1)=Class'UTGame.UTWeap_ImpactHammer'
//    DefWeapons(2)=Class'TaskForces.TFConstructor'
//    DefWeapons(3)=Class'TaskForces.TFWLGun'
    SIGPropsDisplayText(0)="Bounty Amount"
    SIGPropsDisplayText(1)="Outpost Distance"
    SIGPropsDisplayText(2)="Startup Resources"
    SIGPropsDisplayText(3)="Control Capacity"
    SIGPropsDisplayText(4)="Outpost Area Size"
    SIGPropsDisplayText(5)="Generator Rate"
    SIGPropsDisplayText(6)="Construction Areas"
    SIGPropsDisplayText(7)="Minimum Income"
    SIGPropsDisplayText(8)="Skill Amount"
    SIGPropsDisplayText(9)="Enable Warheads"
    SIGPropsDisplayText(10)="Enable Fast Building"
    SIGPropsDisplayText(11)="Territories"
    SIGPropsDisplayText(12)="Max Sentinels"
    SIGPropsDisplayText(13)="Allow Upgrades"
    SIGPropsDisplayText(14)="Unlimited Resouces"
    SIGPropDescText(0)="You will gain this much Energy for killing an enemy."
    SIGPropDescText(1)="The minimum distance one Outpost need to another (measured in meters). Adjust this value according to the size of the map."
    SIGPropDescText(2)="Every player will start the match with this much Energy."
    SIGPropDescText(3)="Your team can spend up to this much Energy for construction. Ouposts increase the maximum."
    SIGPropDescText(4)="Radius of Outpost area will be this much percent of Outpost Distance."
    SIGPropDescText(5)="A standard Generator produces this much Energy per minute."
    SIGPropDescText(6)="When activated, construction is only allowed near Outposts and the BaseCore. The Radius is equal to the Outpost Distance."
    SIGPropDescText(7)="The BaseCore produces this amount of Energy per minute."
    SIGPropDescText(8)="You will gain this much Skill Points for killing an enemy."
    SIGPropDescText(9)="Allows you to turn Warheads on or off."
    SIGPropDescText(10)="Increases building speed for testing purposes."
    SIGPropDescText(11)="When activated, construction is not allowed in enemy territories, structures may still be placed inside your own territory or in no mans land."
    SIGPropDescText(12)="Set the maximum number of deployer Sentinels per person. Leave at 0 for unlimited."
    SIGPropDescText(13)="Allows you to turn Sentinel Upgrades on or off."
    SIGPropDescText(14)="Provides Infinite Resources for testing purposes."
}